{
  "properties" : { },
  "id" : "1458892d21234bc1a27e3f3944582b1f",
  "script" : null,
  "groupId" : "f65c3f8b5be64dea8331b33939d3b2a0",
  "name" : "巡检结果列表模式",
  "createTime" : 1727071098263,
  "updateTime" : 1725271764595,
  "lock" : "0",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "list",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n\"taskId\": \"1819188656790945793\",\r\n\"updateTime\": \"2024-08-23 17:17:10\",\r\n\"current\":2,\r\n\"size\":2\r\n\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": [\n        {\n            \"id\": \"\",\n            \"taskId\": \"\",\n            \"deviceId\": \"D1427906686825217305\",\n            \"ruleId\": \"\",\n            \"result\": \"\",\n            \"updateTime\": \"\",\n            \"deviceName\": \"SN-YL.LingYunFD.R\",\n            \"ip\": \"61.2.5.81\",\n            \"deviceType\": \"1\",\n            \"deptId\": \"\",\n            \"deptName\": \"\",\n            \"ruleName\": \"\",\n            \"auditResult\": [\n                {\n                    \"ruleName\": \"设备cpu\",\n                    \"ruleResult\": \"0%\"\n                },\n                {\n                    \"ruleName\": \"设备内存\",\n                    \"ruleResult\": \"56%\"\n                },\n                {\n                    \"ruleName\": \"设备时延\",\n                    \"ruleResult\": \"14.150001\"\n                },\n                {\n                    \"ruleName\": \"设备丢包率\",\n                    \"ruleResult\": \"0\"\n                }\n            ],\n            \"flag\": \"2\"\n        },\n        {\n            \"id\": \"\",\n            \"taskId\": \"\",\n            \"deviceId\": \"D5181075987056235830\",\n            \"ruleId\": \"\",\n            \"result\": \"\",\n            \"updateTime\": \"\",\n            \"deviceName\": \"SN-YL.LanTaGF.R\",\n            \"ip\": \"61.2.9.55\",\n            \"deviceType\": \"1\",\n            \"deptId\": \"\",\n            \"deptName\": \"\",\n            \"ruleName\": \"\",\n            \"auditResult\": [\n                {\n                    \"ruleName\": \"设备cpu\",\n                    \"ruleResult\": \"0%\"\n                },\n                {\n                    \"ruleName\": \"设备内存\",\n                    \"ruleResult\": \"48%\"\n                },\n                {\n                    \"ruleName\": \"设备时延\",\n                    \"ruleResult\": \"12.775\"\n                },\n                {\n                    \"ruleName\": \"设备丢包率\",\n                    \"ruleResult\": \"0\"\n                },\n                {\n                    \"ruleName\": \"http\",\n                    \"ruleResult\": \"0\"\n                },\n                {\n                    \"ruleName\": \"snmp\",\n                    \"ruleResult\": \"0\"\n                },\n                {\n                    \"ruleName\": \"设备时延\",\n                    \"ruleResult\": \"0\"\n                }\n            ],\n            \"flag\": \"2\"\n        }\n    ]\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Array",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "",
        "value" : "",
        "description" : "",
        "required" : false,
        "dataType" : "Object",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ {
          "name" : "id",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "taskId",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "deviceId",
          "value" : "D8279229554905540079",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "ruleId",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "result",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "updateTime",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "deviceName",
          "value" : "SN_YA.DongZeGF.R",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "ip",
          "value" : "61.2.4.24",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "deviceType",
          "value" : "1",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "deptId",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "deptName",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "ruleName",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        }, {
          "name" : "auditResult",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "Array",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ {
            "name" : "",
            "value" : "",
            "description" : "",
            "required" : false,
            "dataType" : "String",
            "type" : "",
            "defaultValue" : "",
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ {
              "name" : "ruleName",
              "value" : "设备cpu",
              "description" : "",
              "required" : false,
              "dataType" : "String",
              "type" : "",
              "defaultValue" : "",
              "validateType" : "",
              "error" : "",
              "expression" : "",
              "children" : [ ]
            }, {
              "name" : "ruleResult",
              "value" : "1%",
              "description" : "",
              "required" : false,
              "dataType" : "String",
              "type" : "",
              "defaultValue" : "",
              "validateType" : "",
              "error" : "",
              "expression" : "",
              "children" : [ ]
            } ]
          } ]
        }, {
          "name" : "flag",
          "value" : "2",
          "description" : "",
          "required" : false,
          "dataType" : "String",
          "type" : "",
          "defaultValue" : "",
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ ]
        } ]
      } ]
    } ]
  }
}
================================
import java.lang.reflect.Array
import java.util.stream.Collectors
import com.kd.ndmp.biz.desktop.vo.AuditResultVO
import java.util.Optional
import "@/page/page" as page

Map ipMap = new HashMap();


ipMap.put("13.90.2.28", "工作站1");
ipMap.put("13.90.2.29", "工作站2");
ipMap.put("13.90.2.31", "非实时采集服务器");
ipMap.put("13.90.2.32", "路由器采集服务器");
ipMap.put("13.90.1.48", "实时采集服务器");


String free = "空闲大小";
String total = "总量";
String used = "已使"
String dirName = "磁盘地址";
String sysTypeName = "文件系统";
String typeName = "磁盘分区";
String usage = "磁盘"
String cpuNum = "内核数";
String sys = "系统占用数";
String wait = "等待线程数";

var sql = """
       SELECT
           r.result,
            d.ip,
            d.device_name,
            r.device_id,
            d.device_type,
            ar.name rule_name
        FROM
            ndmp_audit_result r
        LEFT JOIN ndmp_device d ON r.device_id = d.ID
        LEFT JOIN ndmp_audit_rule ar ON r.rule_id = ar.ID
        WHERE
          r.task_id =  #{body.taskId}
        <if test="body.updateTime != null ">
            and r.UPDATE_TIME = #{body.updateTime}
        </if>
        <if test="body.updateTime == null ">
            and r.UPDATE_TIME = (SELECT distinct UPDATE_TIME from ndmp_audit_result where task_id = #{body.taskId} ORDER BY UPDATE_TIME DESC LIMIT 1)
        </if>
"""
var list = db.select(sql)

var deviceIdSet = list.stream().map(v -> v.get("deviceId")).collect(Collectors.toSet());



var res = new ArrayList()
for (deviceId in deviceIdSet) {

    var vo = new AuditResultVO();
    var first = list.stream().filter(d -> {
        String deviceId1 = d.get("deviceId");
        if (deviceId1 != null) {
            return deviceId1
                .equals(deviceId);
        } else {
            return false;
        }
    }).findFirst();
    AuditResultVO primitiveVo = null;
    if (first.isPresent()) {
        primitiveVo = first.get();
    }
    if (primitiveVo != null) {
        vo.deviceName = primitiveVo.get("deviceName");
        vo.deviceId = primitiveVo.get("deviceId");
        vo.ip = primitiveVo.get("ip");
        vo.deviceType = primitiveVo.get("deviceType")::string;
    }

    var sameDeviceRuleResult = list.stream().filter(v -> {
        String deviceId1 = v.get("deviceId");
        if (deviceId1 != null) {
            return deviceId1
                .equals(deviceId);
        } else {
            return false;
        }
    }).collect(Collectors.toList());
    var listRes = new ArrayList();
    sameDeviceRuleResult.forEach(v -> {
        Map map = new HashMap();
        map.put("ruleName", v.get("ruleName"));
        String replacedResult = v.get("result")::string.replace("free", free).replace("total", total)
            .replace("usage", usage).replace("dirName", dirName)
            .replace("sysTypeName", sysTypeName).replace("typeName", typeName)
            .replace("cpuNum", cpuNum).replace("sys", sys).replace("wait", wait)
            .replace("used", used);
        map.put("ruleResult", replacedResult);
        listRes.add(map);
    });
    vo.auditResult = listRes;

    res.add(vo);

}


for (vo in list) {
    if (vo.get("ruleName").equals("平台服务器cpu")) {

        res.forEach(v -> {
            v.flag = "1";
            v.ip = v.getDeviceId();
            v.deviceName = MapUtil.getStr(ipMap, v.deviceId());
        });
        break;
    }
    if (vo.get("ruleName").equals("设备cpu")) {

        res.forEach(v -> {
            v.flag = "2";
        });
        break;
    }

}


return {
    total: res.size(),
    records: page(body.current, body.size, res)

}